package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.TeacherDao;
import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherService {
    private TeacherDao teacherDao = new TeacherDao();

    //判断输入工号是否存在
    public boolean isExists(String id) {
        //建立数组接收库管对象
        Teacher[] teachers = teacherDao.findAllTeacher();
        //标记位exists
        boolean exists = false;
        //遍历循环判断
        for (int i = 0; i < teachers.length; i++) {
            //非空校验与equals校验
            if (teachers[i] != null && teachers[i].getId().equals(id)) {
                exists = true;
                break;
            }
        }
        return exists;
    }

    //建立添加老师方法
    public boolean addTeacher(Teacher teacher) {
        return teacherDao.addTeacher(teacher);
    }

    //建立删除老师方法
    public void deleteTeacherById(String delId) {
        teacherDao.delateTeacherById(delId);
    }

    //查看所有老师方法
    public Teacher[] findAllTeacher() {
        Teacher[] teachers = teacherDao.findAllTeacher();
        //标记位思想
        boolean  flag = false;
        //遍历数组判断
        for (int i = 0; i < teachers.length; i++) {
            if(teachers[i]!=null){
                flag = true;
            }
        }
        if(flag){
            return teachers;
        }else{
            return null;
        }
    }

    //修改老师算法
    public void updateTeacher(Teacher teacher) {
        teacherDao.updateTeacher(teacher);
    }
}
